/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GENDATA_COMMON_HH
#define GENDATA_COMMON_HH
//! \addtogroup gendata
//@{

#include <stdlib.h>
#include <stdio.h>

// DEFINITIONS
#define GENDATA_INVALID_VALUE   ((int)0x80000001)

// TYPEDEFS

//! Types of metadata
typedef enum gendata_type_enum
{
    GENDATA_CLASS=0,               // 0
    GENDATA_INHERITANCE,
    GENDATA_MEMBER,
    GENDATA_MEMBER_VECTOR_N_MAX,
    GENDATA_MEMBER_OBJECT,         // 4
    GENDATA_METHOD,
    GENDATA_PARAMETER,
    GENDATA_CHARP,
    GENDATA_OBJECT_POINTER,        // 8
    GENDATA_FUNCTION_POINTER,
    GENDATA_CHAR,
    GENDATA_SUBROUTINE,
    GENDATA_INT,                   // 12
    GENDATA_UNSIGNED_INT,
    GENDATA_FLOAT,
    GENDATA_DOUBLE,
    GENDATA_LONG_LONG,             // 16
    GENDATA_UNSIGNED_LONG_LONG,
    GENDATA_POINTER,
    GENDATA_REFERENCE_COUNT,
    GENDATA_VOID_POINTER,          // 20
    GENDATA_MEMBER_STD_VECTOR_IMPL,
    GENDATA_REFERENCE,
    GENDATA_SHORT,
    GENDATA_UNSIGNED_SHORT,        // 24
    GENDATA_ENUM,
    GENDATA_ENUM_VALUE,
    GENDATA_UNSIGNED_CHAR,
    GENDATA_ARRAY_TYPE,            // 28
    GENDATA_SUBRANGE,
    GENDATA_UNSPEC_PARAM,
    GENDATA_VARIABLE,
    GENDATA_CONST_CHARP,           // 32
    GENDATA_BOOL,
    GENDATA_LAST
} gendata_type;

//! Types of metadata fields
typedef enum gendata_meta_type_enum
{
    GENDATA_GENDATA_TYPE=0,        // 0
    GENDATA_GENDATA_GOTO_NEXT,
    GENDATA_GENDATA_RESERVE,
    GENDATA_GENDATA_VAR,           // number of variable children
    GENDATA_NAME,                  // 4
    GENDATA_DOC,
    GENDATA_SIZE,
    GENDATA_TYPE,
    GENDATA_LOCATION,              // 8
    GENDATA_LINKAGE,
    GENDATA_IS_CTOR,
    GENDATA_ARTIFICIAL,
    GENDATA_NAMESPACE,             // 12
    GENDATA_UPPER_BOUND,
    GENDATA_CONST_VALUE,
    GENDATA_VTABLE,
    GENDATA_VTABLE_LINKAGE,        // 16
    GENDATA_ATTR,
    GENDATA_META_LAST
} gendata_meta_type;


extern const char *gendata_type_strings[];
extern int *gendata_structs[GENDATA_LAST];

// PROTOTYPES
// returns the position for next iteration (NULL if error)
int *gendata_traverse(int *position);

// data points to a gendata_type beginning
// returns the value for the meta_type field in the structure
int gendata_get_data(int *data, gendata_meta_type meta_type, int occurence=0);
// returns the position for the meta_type field in the structure
int gendata_get_position(int *data, gendata_meta_type meta_type);
// returns 1 if metadata type is in the structure
int gendata_has_metatype(int type, gendata_meta_type meta_type, int *position=NULL);
// returns the string if has metadata and content >=0, resolving from doc
char *gendata_get_string(int *data, char *doc, gendata_meta_type meta_type);
// return gendata struct size
int gendata_type_size(gendata_type type);

// dumps metadata int stream
void gendata_dump(FILE *out, int *data, int n_data, char *doc);

// resolve type/pos type (returns -1/NULL in case of error)
int gendata_resolve_type(int *data, int n_indirections=1);
int *gendata_resolve_pos_type(int *data, int n_indirections=1);

// return metadata string as C++ (returns the number of chars written)
int gendata_string_as_cpp(int *data, char *doc, char *buffer, int n_buffer, int color=1);

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	gendata_traverse,
	gendata_get_data,
	gendata_get_position,
	gendata_has_metatype,
	gendata_get_string,
	gendata_type_size,
	gendata_dump,
	gendata_dump_recur,
	gendata_resolve_type,
	gendata_resolve_pos_type,
	gendata_string_as_cpp,
	gendata_type_enum,
	gendata_meta_type_enum,
	gendata_type,
	gendata_type_strings,
	gendata_struct_class,
	gendata_struct_inheritance,
	gendata_struct_member,
	gendata_struct_member_vector_n_max,
	gendata_struct_member_object,
	gendata_struct_method,
	gendata_struct_parameter,
	gendata_struct_charp,
	gendata_struct_object_pointer,
	gendata_struct_function_pointer,
	gendata_struct_char,
	gendata_struct_subroutine,
	gendata_struct_int,
	gendata_struct_unsigned_int,
	gendata_struct_float,
	gendata_struct_double,
	gendata_struct_long_long,
	gendata_struct_unsigned_long_long,
	gendata_struct_pointer,
	gendata_struct_reference_count,
	gendata_struct_void_pointer,
	gendata_struct_member_std_vector_impl,
	gendata_struct_reference,
	gendata_struct_short,
	gendata_struct_unsigned_short,
	gendata_struct_enum,
	gendata_struct_enum_value,
	gendata_struct_unsigned_char,
	gendata_struct_array_type,
	gendata_struct_subrange,
	gendata_struct_unspec_param,
	gendata_struct_variable,
	gendata_struct_const_charp,
	gendata_struct_bool,
	gendata_structs,
	gendata_meta_type:
					~select
   )
*/
